//adventurer random test

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"
#include <math.h>
#include <stdlib.h>
#include <time.h>

#define NOISY_TEST 1

int testNum = 1;

int test()
{
        struct gameState state;
        struct gameState * game = &state;
        int r;

        int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse,sea_hag, tribute, smithy};
        int numPlayers = 2 + rand()%3;
        memset(&state, 23, sizeof(struct gameState));
        r = initializeGame(numPlayers, k, time(NULL), game);
        int drawntreasure = 0;
        int cardDrawn = rand()%26;
        int z = 0;

        int handCount = rand()%MAX_HAND;
        int deckCount = rand()%(MAX_DECK - handCount);
        int discardCount = MAX_DECK - deckCount;
        int currentPlayer = rand()%numPlayers;
        int temphand[MAX_HAND];

        game->deckCount[currentPlayer] = deckCount;
        game->handCount[currentPlayer] = handCount;
        game->discardCount[currentPlayer] = discardCount;

        for (int i = 0; i < deckCount; i++)
                game->deck[currentPlayer][i] = rand()%26;
        for (int j = 0; j < handCount; j++)
                game->hand[currentPlayer][j] = rand()%26;
        for (int k = 0; k < discardCount; k++)
                game->discard[currentPlayer][k] = rand()%26;

        zzzadventurercardplay(drawntreasure, currentPlayer, cardDrawn, temphand, z, game);

        if ((game->handCount[currentPlayer] == handCount + 2) && (game->hand[currentPlayer][game->handCount[currentPlayer] - 1] == copper || silver || gold) &&(game->hand[currentPlayer][game->handCount[currentPlayer] - 2] == copper || silver || gold)){
#if (NOISY_TEST == 1)

                testNum = testNum++;
                printf("zzzadventurercardplay(): PASS when test drawing two treasure cards\n");
                printf("number of players: %d\n", numPlayers);
                printf("currentPlayer: %d\n", currentPlayer);
                printf("handCount: %d\n", handCount);
                               }
#endif
        else {
#if (NOISY_TEST == 1)

                testNum = testNum++;
                printf("zzzadventurercardplay(): FAIL when test drawing two treasure cards\n");
                printf("drawntreasure: %d\n", drawntreasure);
                printf("number of players: %d\n", numPlayers);
                printf("currentPlayer: %d\n", currentPlayer);
                printf("handCount: %d\n", handCount);
                printf("card Drawn: %d\n",  cardDrawn);
#endif
                return -1;
        }

        return 0;
}

int main(int argc, char *argv[])
{
        srand(time(NULL));

        for (int i = 0; i < 15000; i++) {
                if (test() == -1)
                        break;
        }

        return 0;
}

